<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
use Common\Model\Cate;
use Common\Model\Goods;
//前台首页控制器
class IndexController extends Controller{
    //载入首页
    public function index(){
    	//显示头部导航
    	$cateModel=new Cate;
		$cateData=$cateModel->where("pid=0")->orderBy('sort','DESC')->limit(6)->get();
		View::with('cateData',$cateData);
		//显示侧导航
		$nav=$cateModel->where("pid=0")->orderBy('sort','DESC')->limit(8)->get();
		foreach($nav as $k=>$v){
			$cid=$nav[$k]['cid'];
			$nav[$k]['value']=$cateModel->where("pid={$cid}")->limit(4)->get();
		}
		View::with('nav',$nav);
		//显示网站导航
		$navData=$cateModel->where("pid=0")->orderBy('sort','DESC')->get();
		View::with('navData',$navData);
		//轮播图下的推荐商品
		$goodsModel=new Goods;
		$recommendGoods=$goodsModel->where("shop_category_cid=42")->limit(3)->get();
//		p($recommendGoods);
		View::with('recommendGoods',$recommendGoods);
		//显示手机及手机所有的子分类
		//先查询所有手机下的子分类
		$phoneCate=$cateModel->where("pid=1")->lists('cid');
		$phoneCate[]=1;
//		p($phoneCate);
		//显示手机最新上架的四件商品
		$newGoodsData=$goodsModel
			->where("shop_category_cid IN(".implode(',', $phoneCate).")")
			->orderBy('time','DESC')
			->limit(4)->get();
		View::with('newGoodsData',$newGoodsData);
		//显示手机点击量最多的四件商品
		$goodsData=$goodsModel
			->where("shop_category_cid IN(".implode(',', $phoneCate).")")
			->where("shop_category_cid<>42")
			->orderBy('click','DESC')
			->limit(4)->get();
//		p($newGoodsData);
		View::with('goodsData',$goodsData);
		//显示除手机分类之外的商品
		$otherGoodsData=$goodsModel
			->where("shop_category_cid NOT IN(".implode(',', $phoneCate).")")
			->where("shop_category_cid<>42")
			->where("shop_category_cid<>32")
			->limit(7)->get();
//		p($otherGoodsData);
		View::with('otherGoodsData',$otherGoodsData);
		//显示VR眼镜
		$vrData=$goodsModel->where("shop_category_cid=32")->find();
//		p($vrData);
		View::with('vrData',$vrData);
		//显示排行
		$oneGoodsData=$goodsModel
			->where("shop_category_cid NOT IN(".implode(',', $phoneCate).")")
			->where("shop_category_cid<>42")
			->orderBy('click','DESC')
			->limit(8)->get();
//		p($oneGoodsData);
		View::with('oneGoodsData',$oneGoodsData);
    	View::make();
	}
	
}
?>